package com.fly.platform.conf.interceptor

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter

/**
 * @author fly
 * All right reserved
 */
@Configuration
class CorsConfig {

    private fun buildConfig(): CorsConfiguration {

        return CorsConfiguration().apply {

            addAllowedHeader("*")
            addAllowedMethod("*")
            addAllowedOrigin("*")
        }
    }

    @Bean
    fun corsFilter(): CorsFilter {

        val source = UrlBasedCorsConfigurationSource()
        source.registerCorsConfiguration("/**", buildConfig()) //注册
        return CorsFilter(source)
    }
}